<?php

/**
 * This is the model class for table "{{ssctestdetails}}".
 *
 * The followings are the available columns in table '{{ssctestdetails}}':
 * @property string $idssctestdetails
 * @property string $idssctest
 * @property string $testreport
 * @property integer $ssccounter
 *
 * The followings are the available model relations:
 * @property Ssctest $idssctest0
 */
class Ssctestdetails extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Ssctestdetails the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{ssctestdetails}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('idssctest, testreport', 'required'),
			array('ssccounter', 'numerical', 'integerOnly'=>true),
			array('idssctest, testreport', 'length', 'max'=>10),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('idssctestdetails, idssctest, testreport, ssccounter', 'safe', 'on'=>'search'),
                        array('iddispatchdetails', 'autocompleteValidator', 'model'=>'Ssctest'),
		);
	}        
        
        public function autocompleteValidator($attribute,$params){
               $match = addcslashes($_REQUEST[$attribute], '%_');
               if(!new $params['model']->exists(new CDbCriteria( array(
                    'condition' => "$attribute = :$attribute",
                    'params'    => array(":$attribute" => "$match")
                )))){
                    $this->addError($attribute, Yii::t('application', 'Incorrect {attribute}.', array('{attribute}'=>Yii::t('application', $attribute))));
               }
        }      

        public function beforeSave(){
                        if(isset($_REQUEST['iddispatchdetails'])){
                $match = addcslashes($_REQUEST['iddispatchdetails'], '%_'); // escape LIKE's special characters
                $criteria=new CDbCriteria( array(
                    'condition' => 'iddispatchdetails = :iddispatchdetails',
                    'params'    => array(':iddispatchdetails' => "$match")
                ) );            
                $model=Ssctest::model()->find($criteria);
                $this->idssctest = $model->idssctest;
            }
                        return parent::beforeSave();
        }        
        
       
        
        
	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'idssctest0' => array(self::BELONGS_TO, 'Ssctest', 'idssctest'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'idssctestdetails' => Yii::t('application', 'Idssctestdetails'),
			'idssctest' => Yii::t('application', 'Idssctest'),
			'testreport' => Yii::t('application', 'Testreport'),
			'ssccounter' => Yii::t('application', 'Ssccounter'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('idssctestdetails',$this->idssctestdetails,true);
		$criteria->compare('idssctest',$this->idssctest,true);
		$criteria->compare('testreport',$this->testreport,true);
		$criteria->compare('ssccounter',$this->ssccounter);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}